package com.cloudkinto.controller.stock;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.stock.BoxStockByTypeQueryBo;
import com.cloudkinto.bo.stock.ProductStockBySkuQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.dto.stock.query.BoxTypeStockPageDto;
import com.cloudkinto.dto.stock.query.SkuStockPageDto;
import com.cloudkinto.service.stock.ProductStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hua
 * @since 2024-10-28
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "omp库存模块")
@RequestMapping("/api/admin/omp/ProductStock")
public class ProductStockOmpController extends BaseController {
    private final ProductStockService productStockService;

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "查询初始化", notes = "查询初始化")
    public SingleResult pageInit() {
        return productStockService.pageInit(getCurrentUserId(), getTenantId(),getCompanyId(), "omp");
    }

    @UserSessionRequired
    @PostMapping("/listPageBySku")
    @ApiOperation(value = "按产品查询", notes = "按产品查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = SkuStockPageDto.class))
    public PageResult listPageBySku(@RequestBody @Validated ProductStockBySkuQueryBo req) {
        req.setSource("omp");
        req.setUserId(getCurrentUserId());
        req.setTenantId(getTenantId());
        return productStockService.productListPageBySku(req);
    }

    @UserSessionRequired
    @PostMapping("/ompExportBySku")
    @ApiOperation(value = "按产品查询导出", notes = "按产品查询导出")
    public void ompExportBySku(@RequestBody @Validated ProductStockBySkuQueryBo req, HttpServletResponse response) throws IOException {
        req.setSource("omp");
        req.setUserId(getCurrentUserId());
        req.setTenantId(getTenantId());
        productStockService.ompExportBySku(req, response);
    }

    @UserSessionRequired
    @PostMapping("/boxListPageByType")
    @ApiOperation(value = "按箱类型查询", notes = "按箱类型查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = BoxTypeStockPageDto.class))
    public PageResult boxListPageByType(@RequestBody @Validated BoxStockByTypeQueryBo req) {
        req.setSource("omp");
        req.setUserId(getCurrentUserId());
        req.setTenantId(getTenantId());
        return productStockService.boxListPageByType(req);
    }

    @UserSessionRequired
    @PostMapping("/ompExportByBoxTypeNo")
    @ApiOperation(value = "按箱类型查询导出", notes = "按箱类型查询导出")
    public void ompExportByBoxTypeNo(@RequestBody @Validated BoxStockByTypeQueryBo req, HttpServletResponse response) throws IOException {
        req.setSource("omp");
        req.setUserId(getCurrentUserId());
        req.setTenantId(getTenantId());
        productStockService.ompExportByBoxTypeNo(req, response);
    }
}

